//
//  UpMenuView.cpp
//  FruitCrush
//
//  Created by gaoyu on 15/7/28.
//
//

#include "LocalizedStringGetter.h"
#include "DiamondShopMenuItem.h"
#include "MarketMasonryView.h"
#include "GoldSaveModel.h"
#include "ShowGoldView.h"

USING_NS_CC;

#define TITLE_HEIGHT   40
#define MENU_ITEM_Y_PAD  5
#define BACK_MENU_WIDTH 50

typedef enum {
	MarketMenu1 = 1,
	MarketMenu2,
	MarketMenu3,
	MarketMenu4,
	MarketMenu5,
	MarketMenu6,
	MarketBack,
	MarketShowGoldViewTag,
} MenuTag;

typedef enum {
    ZBg,
    ZTitle,
    ZMenu,
} ZIndex;


Scene *MarketMasonryView::createScene()
{
    auto scene = Scene::create();
    auto layer = MarketMasonryView::create();
    scene->addChild(layer);
    return scene;
}

bool MarketMasonryView::init()
{
    if (!Layer::init()) {
        return false;
    }
    bgInit();
    menuInit();
    titleInit();
    return true;
}

void MarketMasonryView::menuInit()
{
	Size winsize = Director::getInstance()->getWinSize();
    auto cache = SpriteFrameCache::getInstance();
	cache->addSpriteFramesWithFile("Diamond.plist");

	auto menuItem1 = DiamondShopMenuItem::create("DiamondMenu.png", "DiamondMenuSelected.png","DiamondMenuSelected.png",
			CC_CALLBACK_1(MarketMasonryView::menuCallback, this));
	menuItem1->setTag(MarketMenu1);
	menuItem1->setAnchorPoint(Vec2::ZERO);
	menuItem1->setTitle(LocalizedStringGetter::getStringByKey("Masonry60"));
	menuItem1->setIcon("DiamondIcon1.png");
	menuItem1->setPrice(LocalizedStringGetter::getStringByKey("Masonry60Price"));
	menuItem1->setPosition(0, winsize.height - menuItem1->getSize().height*1 - MENU_ITEM_Y_PAD -TITLE_HEIGHT);

	auto menuItem2 = DiamondShopMenuItem::create("DiamondMenu.png", "DiamondMenuSelected.png","DiamondMenuSelected.png",
			CC_CALLBACK_1(MarketMasonryView::menuCallback, this));
	menuItem2->setTag(MarketMenu2);
	menuItem2->setAnchorPoint(Vec2::ZERO);
	menuItem2->setTitle(LocalizedStringGetter::getStringByKey("Masonry300"));
	menuItem2->setIcon("DiamondIcon1.png");
	menuItem2->setPrice(LocalizedStringGetter::getStringByKey("Masonry300Price"));
	menuItem2->setInfo(LocalizedStringGetter::getStringByKey("GiveMasonry15"));
	menuItem2->setPosition(winsize.width - menuItem1->getSize().width, winsize.height - menuItem1->getSize().height*1 - MENU_ITEM_Y_PAD -TITLE_HEIGHT);

	auto menuItem3 = DiamondShopMenuItem::create("DiamondMenu.png", "DiamondMenuSelected.png","DiamondMenuSelected.png",
			CC_CALLBACK_1(MarketMasonryView::menuCallback, this));
	menuItem3->setTag(MarketMenu3);
	menuItem3->setAnchorPoint(Vec2::ZERO);
	menuItem3->setTitle(LocalizedStringGetter::getStringByKey("Masonry980"));
	menuItem3->setIcon("DiamondIcon2.png");
	menuItem3->setPrice(LocalizedStringGetter::getStringByKey("Masonry980Price"));
	menuItem3->setInfo(LocalizedStringGetter::getStringByKey("GiveMasonry80"));
	menuItem3->setPosition(0, winsize.height - menuItem1->getSize().height*2 - MENU_ITEM_Y_PAD*2 -TITLE_HEIGHT);

	auto menuItem4 = DiamondShopMenuItem::create("DiamondMenu.png", "DiamondMenuSelected.png","DiamondMenuSelected.png",
			CC_CALLBACK_1(MarketMasonryView::menuCallback, this));
	menuItem4->setTag(MarketMenu4);
	menuItem4->setAnchorPoint(Vec2::ZERO);
	menuItem4->setTitle(LocalizedStringGetter::getStringByKey("Masonry1980"));
	menuItem4->setIcon("DiamondIcon2.png");
	menuItem4->setPrice(LocalizedStringGetter::getStringByKey("Masonry1980Price"));
	menuItem4->setInfo(LocalizedStringGetter::getStringByKey("GiveMasonry200"));
	menuItem4->setPosition(winsize.width - menuItem1->getSize().width, winsize.height - menuItem1->getSize().height*2- MENU_ITEM_Y_PAD*2 -TITLE_HEIGHT);

	auto menuItem5 = DiamondShopMenuItem::create("DiamondMenu.png", "DiamondMenuSelected.png","DiamondMenuSelected.png",
			CC_CALLBACK_1(MarketMasonryView::menuCallback, this));
	menuItem5->setTag(MarketMenu5);
	menuItem5->setAnchorPoint(Vec2::ZERO);
	menuItem5->setTitle(LocalizedStringGetter::getStringByKey("Masonry3280"));
	menuItem5->setIcon("DiamondIcon3.png");
	menuItem5->setPrice(LocalizedStringGetter::getStringByKey("Masonry3280Price"));
	menuItem5->setInfo(LocalizedStringGetter::getStringByKey("GiveMasonry15"));
	menuItem5->setPosition(0, winsize.height - menuItem1->getSize().height*3 - MENU_ITEM_Y_PAD*3 -TITLE_HEIGHT);

	auto menuItem6 = DiamondShopMenuItem::create("DiamondMenu.png", "DiamondMenuSelected.png","DiamondMenuSelected.png",
			CC_CALLBACK_1(MarketMasonryView::menuCallback, this));
	menuItem6->setTag(MarketMenu6);
	menuItem6->setAnchorPoint(Vec2::ZERO);
	menuItem6->setTitle(LocalizedStringGetter::getStringByKey("Masonry6480"));
	menuItem6->setIcon("DiamondIcon3.png");
	menuItem6->setPrice(LocalizedStringGetter::getStringByKey("Masonry6480Price"));
	menuItem6->setInfo(LocalizedStringGetter::getStringByKey("GiveMasonry1800"));
	menuItem6->setPosition(winsize.width - menuItem1->getSize().width, winsize.height - menuItem1->getSize().height*3 - MENU_ITEM_Y_PAD*3 -TITLE_HEIGHT);

	auto menuItemBack = MenuItemImage::create("WinBackButton.png", "WinBackButton.png","WinBackButton.png",
			CC_CALLBACK_1(MarketMasonryView::menuCallback, this));
	menuItemBack->setTag(MarketBack);
	menuItemBack->setAnchorPoint(Vec2::ZERO);
	menuItemBack->setPosition(Point(winsize.width - BACK_MENU_WIDTH,winsize.height - BACK_MENU_WIDTH));

    auto menu = Menu::create(menuItem1, menuItem2, menuItem3, menuItem4, menuItem5, menuItem6,menuItemBack, NULL);
    menu->setAnchorPoint(Vec2::ZERO);
    menu->setPosition(Vec2::ZERO);
    addChild(menu,ZMenu);

}

void MarketMasonryView::titleInit()
{
	Size size = Director::getInstance()->getWinSize();
	ShowGoldView *goldView = ShowGoldView::create();
	goldView->setPosition(Point(GOLD_VIEW_LEFT_PAD,size.height - GOLD_VIEW_TOP_PAD));
	goldView->unVisableButton();
    addChild(goldView,ZTitle,MarketShowGoldViewTag);
}

void MarketMasonryView::menuCallback(Ref *sender)
{
	DiamondShopMenuItem *item = (DiamondShopMenuItem*)sender;
	switch (item->getTag()) {
	case MarketBack:
		Director::getInstance()->popScene();
		break;
	default:
		break;
	}
}

void MarketMasonryView::bgInit()
{
    auto bg = Sprite::create("DiamondScreenBg.png");
    bg->setAnchorPoint(Vec2::ZERO);
    bg->setPosition(Vec2::ZERO);
    this->addChild(bg);
}

